home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / dbase / kf2ex.lha / KingFisher-Distribution / Developer / ReOrder.c < prev    next >
C/C++ Source or Header  |  1995-03-04  |  5KB  |  171 lines

  1. /****************************************************************************
  2. * KingFisher 2.0 Database ReOrdering Tool
  3. * Copyright © 1994 by Udo Schuermann
  4. * All rights reserved
  5. * ------------------------------------------------------------------------
  6. * Demonstration of a KingFisher 2.0 API-based interface.
  7. * This program uses two handles to the database.
  8. * This program is available only to registered users of KingFisher.
  9. * DO NOT REDISTRIBUTE!
  10. ****************************************************************************/
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <dos.h>
  16.  
  17. #include "kf-api.h"
  18.  
  19.  
  20. #define VERSION "1.3"
  21.  
  22. #ifndef __MYDATE__
  23. #define __MYDATE__ __AMIGADATE__
  24. #endif
  25.  
  26. char Version[] = "$VER: ReOrder "VERSION" for KingFisher "__MYDATE__;
  27.  
  28. int brk(void) {
  29.   printf("\n(CTRL-C RECEIVED)");
  30.   fflush(stdout);
  31.   ExitRequested = TRUE;
  32.   return 0;
  33. }
  34.  
  35.  
  36. void SwapBuffers( struct KFMsg *M1, struct KFMsg *M2 );
  37.  
  38.  
  39. void main(int argc, char *argv[]) {
  40.   
  41.   struct KFMsg *Handle1,*Handle2;
  42.   BOOL happy=TRUE,ExitRequestReported=FALSE;
  43.  
  44.   onbreak(&brk);
  45.  
  46.   printf("ReOrder "VERSION" for KingFisher Release 2\n"
  47.      "Copyright \© 1994 by Udo Schuermann\n"
  48.      "All rights reserved\n\n");
  49.  
  50.   if( argc < 3 ) {
  51.     printf("Usage: ReOrder input output [ start [ count ] ]\n"
  52.        "  input   The name of a .kfdb database from which ReOrder will read\n"
  53.        "  output  The name of a .kfdb database to which ReOrder will append\n"
  54.        "          records read from the input database.\n"
  55.        "  start   The record (1+) at which the transfer is to begin.\n"
  56.        "  count   The maximum number of records (1+) to be transferred.\n"
  57.        "\n"
  58.        "This tool allows you to easily alter the partitioning of a database\n"
  59.        "by specifying a new .kfdb file with a different partitioning.  Care\n"
  60.        "should be exercised to assure that filenames in the new database do\n"
  61.        "not conflict with the old one, and that enough sections are defined\n"
  62.        "to store the output.\n"
  63.        "   Data will be appended to the end of the output database, without\n"
  64.        "disturbing existing records.\n"
  65.        "   ReOrder uses two logins to the KingFisher Server.\n");
  66.     return;
  67.   }
  68.  
  69.   if( Handle1 = KFLogin( "ReOrder Input Client" ) ) {
  70.     if( Handle2 = KFLogin( "ReOrder Output Client" ) ) {
  71.       if( KFSelectDatabase( Handle1, argv[1] ) ) {
  72.     if( KFSelectDatabase( Handle2, argv[2] ) ) {
  73.       ULONG Counter = -1L;
  74.       ULONG FishID  = 0;
  75.       BOOL ExitRequestReported = FALSE;
  76.  
  77.       /* Process additional (optional) parameters */
  78.       if( argc > 2 )
  79.         if( KFSelectFish( Handle1, FishID=atol(argv[3]) ) )
  80.           printf("Beginning transfer with record %d\n",FishID);
  81.         else {
  82.           printf("Unable to select record \"%s\"\n",FishID);
  83.           happy = FALSE;
  84.         } /* if */
  85.       if( happy && (argc > 3) ) {
  86.         if( (Counter = atol(argv[4])) > 0 )
  87.           printf("Transfer will copy up to %d records\n",Counter);
  88.         else {
  89.           printf("Unable to determine how many \"%s\" records is.\n",argv[4]);
  90.           happy = FALSE;
  91.         }
  92.       }
  93.  
  94.       if( happy )
  95.         printf("Now transferring records from one to the other database...");
  96.       fflush(stdout);
  97.  
  98.       /* Main Loop */
  99.       while( happy && Counter ) {
  100.         if( ExitRequested )
  101.           if( !ExitRequestReported ) {
  102.         printf("\n***** RECEIVED REQUEST TO SHUT DOWN (USE ^C TO HONOR IT)\n"
  103.                "Continuing with transfer until done or canceled...");
  104.         ExitRequestReported = TRUE;
  105.         ExitRequested = FALSE;  /* speed up the loop a little */
  106.           }
  107.         if( !KFGetFish( Handle1, FishID ) ) {
  108.           printf("\nUnable to load fish!\n");
  109.           happy = FALSE;
  110.         } else
  111.           if( !KFCurDisk( Handle1 ) ) {
  112.         printf("\nUnable to get fish's disk number!\n");
  113.         happy = FALSE;
  114.           } else {
  115.         /* Swapping buffers is faster than a strcpy() of buffer contents */
  116.         SwapBuffers( Handle1, Handle2 );
  117.  
  118.         happy = KFAddFish( Handle2, KF_DISK(Handle1), KF_FLAGS(Handle1), KF_NIL_FISH, KF_NIL_FISH );
  119.  
  120.         /* Technically, this is not required, as both buffers ought to be
  121.          * the same size and both sufficient for the operations.  We'll
  122.          * just do it here for orthogonality and stylistic correctness.
  123.          */
  124.         SwapBuffers( Handle1, Handle2 );
  125.  
  126.         if( happy ) {
  127.           if( !KFNextFish( Handle1 ) ) {
  128.             if( KF_ERR(Handle1) == kfeNOMORE )
  129.               printf("\nTransfer completed!\n");
  130.             else
  131.               printf("\nUnable to advance to next fish!\n");
  132.             happy = FALSE;
  133.           } else {
  134.             Counter--;
  135.             FishID++;
  136.           }
  137.         } else {
  138.           printf("\nUnable to add fish to the database!\n");
  139.           happy = FALSE;
  140.         }
  141.           }
  142.       } /* while */
  143.     } else
  144.       printf("Unable to open the output database \"%s\"\n",argv[2]);
  145.       } else
  146.     printf("Unable to open the input database \"%s\"\n",argv[1]);
  147.       KFLogout( Handle2 );
  148.     } else
  149.       printf("Unable to obtain second (output) connection to server!\n");
  150.     KFLogout( Handle1 );
  151.     if( ExitRequested || ExitRequestReported )
  152.       printf("\nExit request has been honored!\n");
  153.     printf("Bye-bye!\n");
  154.   } else
  155.     printf("KingFisher Release 2 Server is not running or has no free connections!\n"
  156.        "Please start the server first and/or try again later!\n");
  157. } /* main() */
  158.  
  159.  
  160. void SwapBuffers( struct KFMsg *M1, struct KFMsg *M2 ) {
  161.  
  162.   char  *tBuffer = M1->Buffer;
  163.   ULONG tBufSize = M1->BufferSize;
  164.  
  165.   M1->Buffer     = M2->Buffer;
  166.   M1->BufferSize = M2->BufferSize;
  167.  
  168.   M2->Buffer     = tBuffer;
  169.   M2->BufferSize = tBufSize;
  170. } /* SwapBuffers() */
  171.